import { APIPCPREFIX } from '@/common';
import { request } from '../request';
/**
 * @description 获取颁发证书列表
 */

export const getCertInfo = () =>
  request({
    method: 'post',
    url: APIPCPREFIX + 'safePlanTask/getCertInfo',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
  });

/**
 *获取各个题型最大数量
 *  */
export const getQuestionNum = () =>
  request({
    method: 'post',
    url: APIPCPREFIX + 'safePlanTask/getQuestionNum',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
  });

/**
 *添加考试计划
 *  */
export const createExaminPlan = (data: any) =>
  request({
    method: 'post',
    url: APIPCPREFIX + 'safePlanTask/newAdd',
    data,
  });

/**
 * 分页搜索考试计划列表
 */

export type statusType = 100 | 200 | 300 | 400; //状态 100：待发布 200 ：已发布 300：已结束 400：已过期

export interface ExamPlanListSearchParams {
  title?: string;
  entId?: string;
  status?: statusType;
  source?: 100 | 200; // 100:企业主体 200:主管部门
}

export interface ExamPlanListItem {
  guid: string;
  entId: string;
  source: 100 | 200;
  status: statusType;
  startTime: string;
  endTime: string;
  issueTime: string; //发布时间
  finishTime: string; //完成时间
  modelType: 1 | 2; //1:常规卷，2：练习卷
  className: string;
}

export async function searchExaminPlanList(
  { title, entId, status, source }: ExamPlanListSearchParams,
  pageIndex = 1,
  pageSize = 10,
) {
  const { data } = await request<{ list: ExamPlanListItem[]; total: number }>({
    url: APIPCPREFIX + 'safePlanTask/list',
    params: {
      pageNum: pageIndex,
      pageSize: pageSize,
      entId,
      type: 300, //100：视频 200 图文 300 考试
      taskType: 300, //100学习计划 300考试计划
      source,
      title,
      status,
    },
    noAutoShowErrorMessage: true,
  });

  return data;
}

/**
 * @description 删除考试计划
 */
export const deleteExamPlan = (params: any) =>
  request({
    method: 'post',
    url: APIPCPREFIX + 'safePlanTask/remove',
    params,
  });

/**
 * @description 结束考试计划
 */
export const endExamPlan = (guid: string) =>
  request({
    method: 'post',
    url: APIPCPREFIX + `safePlanTask/finish/${guid}`,
  });
